package org.nstack.network.service.eip;

import org.nstack.network.service.vip.VipVO;
import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.message.APICreateMessage;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;
import org.nstack.header.vm.VmNicVO;


@Action(category = EipConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/eips",
        method = HttpMethod.POST,
        responseClass = APICreateEipEvent.class,
        parameterName = "params"
)
public class APICreateEipMsg extends APICreateMessage {

    @APIParam(maxLength = 255)
    private String name;

    @APIParam(required = false, maxLength = 2048)
    private String description;

    @APIParam(resourceType = VipVO.class, checkAccount = true, operationTarget = true)
    private String vipUuid;

    @APIParam(required = false, resourceType = VmNicVO.class, checkAccount = true, operationTarget = true)
    private String vmNicUuid;

    public String getVipUuid() {
        return vipUuid;
    }

    public void setVipUuid(String vipUuid) {
        this.vipUuid = vipUuid;
    }

    public String getVmNicUuid() {
        return vmNicUuid;
    }

    public void setVmNicUuid(String vmNicUuid) {
        this.vmNicUuid = vmNicUuid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
 
    public static APICreateEipMsg __example__() {
        APICreateEipMsg msg = new APICreateEipMsg();

        msg.setName("Test-EIP");
        msg.setVipUuid(uuid());
        msg.setVmNicUuid(uuid());

        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Created").resource(((APICreateEipEvent)evt).getInventory().getUuid(), EipVO.class.getSimpleName())
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }

}
